{include file="public/_meta" /}
<body>
<div class="wrapper">

    {include file="public/_header" /}

    <!-- Sidebar -->
    {include file="public/_menu" /}
    <!-- End Sidebar -->

    <div class="main-panel">

        <div class="content">
            <div class="page-inner">

                <!-- 面包屑 -->
                {include file="public/_page_header" /}

                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-header">
                                <div class="d-flex align-items-center">
                                    <h4 class="card-title">落地页列表</h4>
<!--                                    <button class="btn btn-primary btn-round ml-auto" data-toggle="modal" data-target="#addRowModal" onClick="add_item(0)">-->
<!--                                        <i class="fa fa-plus"></i>-->
<!--                                        同步落地页-->
<!--                                    </button>-->
                                    <button class="btn btn-info btn-round ml-auto" data-toggle="modal" data-target="#addRowModal3" onclick="add_item(0)">
                                        <i class="fa fa-plus"></i>
                                        新增落地页
                                    </button>
                                </div>

                                <form class="row">

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="ac_name" value="{$ac_name}" placeholder="账户名称">
                                        </div>
                                    </div>

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="adv_id" value="{$adv_id}" placeholder="账户ID">
                                        </div>
                                    </div>

                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <input type="text" class="form-control" name="pro_name" value="{$pro_name}" placeholder="请输入产品名称">
                                        </div>
                                    </div>



                                    <div class="col-md-6 col-lg-2">
                                        <div class="form-group">
                                            <button type="submit" class="btn btn-primary">查询</button>
                                            <a href="{:url('page/index')}" class="btn btn-info" style="color: white;position: absolute;left: 110px;">重置</a>
                                        </div>
                                    </div>

                                </form>

                            </div>


                            <div class="card-body">
                                <!-- Modal 同步 -->
                                <div class="modal fade" id="addRowModal" tabindex="-1" role="dialog" aria-hidden="true">
                                    <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                            <div class="modal-header no-bd">
                                                <h5 class="modal-title">
                                                    <span class="fw-mediumbold">同步</span>

                                                </h5>
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                    <span aria-hidden="true">&times;</span>
                                                </button>
                                            </div>
                                            <div class="modal-body">
                                                <form id="form-modal">
                                                    <div class="row">

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="pro_id" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">同步媒体</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <select class="form-control input-full" name="channel_id">
                                                                    {volist name="channels" id="vo"}
                                                                    <option value="{$vo.id}">{$vo.name}</option>
                                                                    {/volist}
                                                                </select>
                                                            </div>
                                                        </div>

                                                    </div>
                                                    <div class="modal-footer no-bd">
                                                        <button type="submit" id="addRowButton" class="btn btn-primary">同步</button>
                                                        <button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>
                                                    </div>
                                                </form>
                                            </div>

                                        </div>
                                    </div>
                                </div>

                                <!-- Modal2 关联产品 -->
                                <div class="modal fade" id="addRowModal2" tabindex="-1" role="dialog" aria-hidden="true">
                                    <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                            <div class="modal-header no-bd">
                                                <h5 class="modal-title">
                                                    <span class="fw-mediumbold">关联产品</span>

                                                </h5>
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                    <span aria-hidden="true">&times;</span>
                                                </button>
                                            </div>
                                            <div class="modal-body">
                                                <form id="form-modal2">
                                                    <div class="row">

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="pro_id" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">落地页名称</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" id="page_name" disabled>
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="pro_id" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">产品名称</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <select class="form-control input-full" id="pro_id" name="pro_id">
                                                                    <option value="0">请选择</option>
                                                                    {volist name="products" id="vo"}
                                                                    <option value="{$vo.id}">{$vo.name}</option>
                                                                    {/volist}
                                                                </select>
                                                            </div>
                                                        </div>


                                                    </div>
                                                    <div class="modal-footer no-bd">
                                                        <input type="hidden" name="id" value="">
                                                        <button type="submit" id="addRowButton2" class="btn btn-primary">保存</button>
                                                        <button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>
                                                    </div>
                                                </form>
                                            </div>

                                        </div>
                                    </div>
                                </div>

                                <!-- 新增 -->
                                <div class="modal fade show" id="addRowModal3" tabindex="-1" role="dialog" aria-hidden="true">
                                    <div class="modal-dialog" role="document">
                                        <div class="modal-content">
                                            <div class="modal-header no-bd">
                                                <h5 class="modal-title">
                                                    <span class="fw-mediumbold">新增</span>

                                                </h5>
                                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                                    <span aria-hidden="true">×</span>
                                                </button>
                                            </div>
                                            <div class="modal-body">
                                                <form id="form-modal3" novalidate="novalidate">
                                                    <div class="row">

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="pro_id" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">落地页类型</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <select class="form-control input-full" name="landingpage_type">
                                                                    <option value="1">建站</option>
                                                                    <option value="2">自开发</option>
                                                                </select>
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="pro_id" class="col-md-3 col-form-label">回传线索媒体</label>
                                                            <div class="col-md-8 p-0">
                                                                <select class="form-control input-full" name="channel_type">
                                                                    <option value="1">巨量</option>
                                                                    <option value="2">腾讯</option>
                                                                    <option value="3">百度</option>
                                                                    <option value="4">UC</option>
                                                                    <option value="5">快手</option>
                                                                </select>
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="pro_id" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">同步账号</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <div class=" layui-form">
                                                                    <select lay-verify="required" lay-search=""  name="acc_id" id="acc_id">
                                                                        {volist name="accounts" id="vo"}
                                                                        <option value="{$vo.id}">{$vo.acc_name}【{$vo.adv_id}】</option>
                                                                        {/volist}
                                                                    </select>
                                                                </div>
                                                                <!--<select class="form-control input-full" name="acc_id">
                                                                    <option value="0">&#45;&#45;请选择&#45;&#45;</option>
                                                                    {volist name="accounts" id="vo"}
                                                                    <option value="{$vo.id}">{$vo.acc_name}【{$vo.adv_id}】</option>
                                                                    {/volist}

                                                                </select>-->
                                                            </div>

                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="pro_id" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">关联产品</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <select class="form-control input-full" name="pro_id">
                                                                    {volist name="products" id="vo"}
                                                                    <option value="{$vo.id}">{$vo.name}</option>
                                                                    {/volist}

                                                                </select>
                                                            </div>
                                                        </div>

<!--                                                        <div class="form-group form-inline col-md-12">-->
<!--                                                            <label for="pro_id" class="col-md-3 col-form-label">短信签名</label>-->
<!--                                                            <div class="col-md-8 p-0">-->
<!--                                                                <input type="text" class="form-control input-full" name="sms_signname">-->
<!--                                                            </div>-->
<!--                                                        </div>-->

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="pro_id" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">落地页名称</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" name="page_name">
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="pro_id" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">落地页id</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" name="page_id">
                                                            </div>
                                                        </div>

                                                        <div class="form-group form-inline col-md-12">
                                                            <label for="pro_id" class="col-md-3 col-form-label"><font style="vertical-align: inherit;">落地页链接</font></label>
                                                            <div class="col-md-8 p-0">
                                                                <input type="text" class="form-control input-full" name="online_url">
                                                            </div>
                                                        </div>

                                                    </div>
                                                    <div class="modal-footer no-bd">
                                                        <button type="submit" id="addRowButton3" class="btn btn-primary">新增</button>
                                                        <button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>
                                                    </div>
                                                </form>
                                            </div>

                                        </div>
                                    </div>
                                </div>

                                <div class="table-responsive">
                                    <table id="add-row" class="display table table-striped table-hover" >
                                        <thead>
                                        <tr>
                                            <th>ID</th>
                                            <th>落地页类型</th>
                                            <th>媒体名称</th>
                                            <th>账户名称</th>
                                            <th>落地页ID</th>
                                            <th>落地页名称</th>
                                            <th>落地页地址</th>
                                            <th>关联产品</th>
                                            <th>操作人</th>
                                            <th>创建时间</th>
                                            <th>同步时间</th>
                                            <th style="width: 10%">操作</th>
                                        </tr>
                                        </thead>

                                        <tbody>

                                        {volist name="infos" id="vo"}
                                        <tr>
                                            <td>{$vo.id}</td>
                                            <td>{$vo.landingpage_type}</td>
                                            <td>{$vo.channel_name}</td>
                                            <td>{$vo.acc_name}【{$vo.adv_id}】</td>
                                            <td>{$vo.page_id}</td>
                                            <td>{$vo.page_name}</td>
                                            <td><a href="{$vo.online_url}" target="_blank">{$vo.online_url}</a></td>
                                            <td>{$vo.pro_name}</td>
                                            <td>{$vo.admin_id | getRealnameByUid}</td>
                                            <td>{$vo.online_time}</td>
                                            <td>{$vo.create_time}</td>
                                            <td>
                                                <div class="form-button-action">
                                                    <button type="button" title="编辑" class="btn btn-link btn-primary btn-lg" data-toggle="modal" data-target="#addRowModal2" onClick="edit_item('{$vo.id}')">
                                                        <i class="fa fa-edit"></i>关联产品
                                                    </button>

                                                    <button type="button" data-toggle="tooltip" onClick="admin_del(this,'{$vo.id}')" title="" class="btn btn-link btn-danger" data-original-title="删除">
                                                        <i class="fa fa-times"></i>删除
                                                    </button>
                                                </div>
                                            </td>
                                        </tr>
                                        {/volist}

                                        </tbody>
                                    </table>

                                    <!-- 分页 (调取通用方法)-->
                                     <div class="layui-box layui-laypage layui-laypage-molv">{:pagination($infos)}</div>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>


            </div>
        </div>

        {include file="public/_footer" /}


    </div>



</div>

{include file="public/_js" /}

</body>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
    var SCOPE = {
        'delete_url':"{:url('page/delete')}",
        'item_url':"{:url('page/edit')}",
        'edit_url':"{:url('page/save')}",
        'syn_url':"{:url('page/syn_page')}",
        'add_url':"{:url('page/add')}",
    };


    $(function(){
        var commitStatus = false;
        /*表单验证*/
        $("#form-modal").validate({
            rules:{

            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var url = SCOPE.syn_url;
                if(commitStatus==true){
                    return false;
                }
                var loading = layer.load('加载中...', {
                    shade: [0.3,'#fff'] //0.1透明度的白色背景
                });
                /*表单提交*/
                $(form).ajaxSubmit({
                    type: 'post',
                    url: url,
                    success: function(data){
                        layer.close(loading);
                        if(data.code == 1001){
                            commitStatus = true;
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000
                            }, function(){
                                parent.location.reload();
                            });
                        }else{
                            layer.msg(data.msg,{icon:2,time:2000});
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg(errorThrown,{icon:2,time:2000});
                    }
                });

            }
        });

        $("#form-modal2").validate({
            rules:{

            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var url = SCOPE.edit_url;
                if(commitStatus==true){
                    return false;
                }

                /*表单提交*/
                $(form).ajaxSubmit({
                    type: 'post',
                    url: url,
                    success: function(data){
                        if(data.code == 1001){
                            commitStatus = true;
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000
                            }, function(){
                                parent.location.reload();
                            });
                        }else{
                            layer.msg(data.msg,{icon:2,time:2000});
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg(errorThrown,{icon:2,time:2000});
                    }
                });

            }
        });

        $("#form-modal3").validate({
            rules:{

            },
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var url = SCOPE.add_url;
                if(commitStatus==true){
                    return false;
                }

                /*表单提交*/
                $(form).ajaxSubmit({
                    type: 'post',
                    url: url,
                    success: function(data){
                        if(data.code == 1001){
                            commitStatus = true;
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000
                            }, function(){
                                parent.location.reload();
                            });
                        }else{
                            layer.msg(data.msg,{icon:2,time:2000});
                        }
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg(errorThrown,{icon:2,time:2000});
                    }
                });

            }
        });


    });

    function add_item(id) {
        document.getElementById('form-modal').reset();
    }

    function edit_item(id) {
        $.ajax({
            type: 'GET',
            url: SCOPE.item_url,
            dataType: 'json',
            data: {id:id},
            success: function(res){
                if(res.code == 1001){
                    $("input[name='id']").val(id);
                    $("#pro_id").val(res.data.pro_id);
                    $("#page_name").val(res.data.page_name);
                }else{
                    layer.msg(res.msg,{icon:2,time:2000});
                }

            },
            error:function(res) {
                layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
            }
        });
    }


    /*删除*/
    function admin_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'POST',
                url: SCOPE.delete_url,
                dataType: 'json',
                data: {id:id},
                success: function(data){
                    if(data.code == 1001){
                        $(obj).parents("tr").remove();
                        layer.msg('删除方案成功!',{icon:1,time:2000});
                    }else{
                        layer.msg(data.msg,{icon:2,time:2000});
                    }

                },
                error:function(data) {
                    layer.msg('网络错误,稍后再试...',{icon:2,time:2000});
                }
            });
        });
    }

</script>
<script src="__STATIC__/layui/layui.js"></script>
<script>
    layui.use(['form'], function() {
        var form = layui.form;
    });

</script>
</html>